package com.changgou.sms;

import com.alibaba.fastjson.JSON;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
* @Author: 少迪
* @Date: Created in 2019-08-09 11:19
* @Description:
* @Version: 1.0
*/

@Component
@RabbitListener(queues = "sms")
public class SmsListener {


    @Autowired
    private SmsUtil smsUtil;

    @Value("${smsCode}")
    private String smsCode;

    @Value("${param}")
    private String param;

    @RabbitHandler
    public void sendSms(String message){
        System.out.println("接收到消息"+message);
        Map<String,String> map = JSON.parseObject(message, Map.class);
        String phone = map.get("mobile");
        String code=map.get("code");
        System.out.println("手机号："+phone+"验证码："+code);

        //调用阿里云通信。。。
        smsUtil.sendSms(phone, smsCode, param.replace("[value]", code));
    }
}
